package grape.workflow.service.comment.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.workflow.service.comment.api.IWorkflowCommentService;
import grape.workflow.service.comment.dto.CommentDto;
import grape.workflow.service.comment.mapper.CommentMapper;
import grape.workflow.service.comment.query.CommentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by yangwei
 * Created at 2020/6/24 10:35
 */
@Service
public class WorkflowCommentServiceImpl implements IWorkflowCommentService {


    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<CommentDto> list(CommentQuery commentParam) {
        return commentMapper.list(commentParam);
    }

    @Override
    public IPage<CommentDto> listPage(IPage<CommentDto> page, CommentQuery commentParam) {
        return commentMapper.listPage(page, commentParam);
    }

    @Override
    public CommentDto getOne(CommentQuery commentParam) {
        List<CommentDto> list = list(commentParam);
        if (isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public CommentDto insert(CommentDto commentDto) {
        commentDto.setId(UUID.randomUUID().toString());
        commentDto.setTime(new Date());
        boolean r = commentMapper.insert(commentDto);
        if (r) {
            return commentDto;
        }
        return null;
    }
}
